<!DOCTYPE HTML>
<html>
<HEAD>
<meta charset="utf-8">
<TITLE>部门管理</TITLE>
</HEAD>
<body>
    
<?php
include("base-class.php");
include_once('DB.php');

$DB = new DB();

//获取当前页码
if($_GET["page"]){
    $page=intval($_GET["page"]);
}else { 
    $page = 0;
}

//获取操作标识传入，过滤html，js
$action=$_GET["action"];
$action= string::un_script_code($action);
$action= string::un_html($action);


//是否删除
if($action=="del")
{
    //获取部门ID号传入
    $class_id=intval($_GET["class_id"]);
    //获取当前时间
    $nowtime=date("Y/m/d H:i:s",time());
	$DB->query("update class set status=0,edittime='$nowtime' where class_id=$class_id");    
    echo "<script>alert('操作成功！');location='class_manager.php?page=$page';</Script>";
    exit;    
}    
//列表数据获取、分页

//计算总数
$res=$DB->query("select * from class where status=1");
$count = mysql_num_rows($res);


//如果数据表里有数据
if($count)
{
    //每页显示记录数
    $page_num = 10;
    //如果无页码参数则为第一页
    if ($page == 0) $page = 1;
    //计算开始的记录序号
    $from_record = ($page - 1) * $page_num;
    //获取符合条件的数据
    $class_list=$DB->get_all("select A.class_id,A.class_name,B.class_name as fclass_name
                from class A left join class B on A.class_fid=B.class_id where A.status=1 
                order by A.class_id asc limit $from_record,$page_num");
				
	
//自定义操作  class_list
	//$class_list的操作
	//$class_list=$mysql->getData("select * from class");
	//echo "class_list".$class_list;
    //分页函数
    $multi = multi($count, $page_num, $page, "class_manager.php");

}
?>
     <b>华视文化公司通讯录管理</b>
    <!--页面名称-->
	<h3>部门管理<a href="class_add.php">新增部门>></a></h3>
    <!--列表开始-->
    
    <table border=1>
        <tr bgcolor="gray">
            <td>序号</td><td>部门名称</td><td>所属上级</td><td>操作</td>
        </tr>
        <?php
			if($class_list)
            {
                $id = 1; 
                foreach($class_list as $value)
                {
                    if(  $id%2==1){
                           echo "<tr>";
                    }
                    else {
                        echo "<tr bgcolor='gray'>";
                    }
                    echo "
                          <td>$value[class_id]</td>
                          <td><a href='roster_manager.php?class_id=$value[class_id]'>$value[class_name]</a></td>
                          <td>$value[fclass_name]</td>
                          <td>
                            <a href='class_manager.php?action=del&class_id=$value[class_id]'>删除</a>
                            <a href='class_add.php?class_id=$value[class_id]'>修改</a>
                          </td>
                          <tr>";
                    
                     $id++;
                }
            }
			else
            {
			
                echo "<tr><td colspan=4>无记录</td></tr>";
            }
        ?>
    
    </table>
    <?php
	echo $multi;
    ?>
</body>
</html>
